package demo;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import http.code.HttpClient;
import http.code.HttpResult;

public class RegService {

    public static void main(String[] args) throws Exception {
        HttpClient client = new HttpClient();
        // HttpResult result =
        // client.post("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=6387e90a-da2f-4202-8384-10f913e9b66f",
        // headers, msg.getBytes());
        // System.out.println(result.getCode());

        // 注册服务
        // HttpResult result =
        // client.put("http://192.168.32.169:8848/nacos/v1/ns/instance?serviceName=ykb-httpd-a.base&ip=192.168.32.169&port=15005",
        // null, null);
        // System.out.println(result.getCode());
        // System.out.println(new String(result.getBody()));

        HttpResult result;

        result = client.put(
                "http://192.168.32.169:8848/nacos/v1/ns/instance?serviceName=k8s-spring-cloud-test.base&ip=10.43.39.114&port=15005",
                null, null);
        System.out.println(result.getCode());
        System.out.println(new String(result.getBody()));

        result = client.put(
                "http://192.168.32.169:8848/nacos/v1/ns/instance?serviceName=k8s-spring-cloud-admin.base&ip=10.43.39.114&port=15005",
                null, null);
        System.out.println(result.getCode());
        System.out.println(new String(result.getBody()));

        // result =
        // client.post("http://192.168.32.169:8848/nacos/v1/ns/service",null,
        // "serviceName=ykb-httpd-a.base:14000&protectThreshold=0".getBytes());
        // System.out.println(result.getCode());
        // System.out.println(new String(result.getBody()));

        HttpResult rep      = null;
        for (;;) {

            //http://192.168.32.169:8848/nacos/v1/ns/instance/beat?serviceName=k8s-spring-cloud-test.base
            //beat={"cluster":"DEFAULT","ip":"10.43.39.114","metadata":{},"port":15005,"scheduled":true,"serviceName":"k8s-spring-cloud-test.base","weight":1}
            rep = client.put(
                    "http://192.168.32.169:8848/nacos/v1/ns/instance/beat?serviceName=k8s-spring-cloud-test.base&beat=%7b%22cluster%22%3a%22DEFAULT%22%2c%22ip%22%3a%2210.43.39.114%22%2c%22metadata%22%3a%7b%7d%2c%22port%22%3a15005%2c%22scheduled%22%3atrue%2c%22serviceName%22%3a%22k8s-spring-cloud-test.base%22%2c%22weight%22%3a1%7d",
                    null, null);
            // System.out.println(rep.getCode());
            // System.out.println(new String(rep.getBody()));

            rep = client.put(
                    "http://192.168.32.169:8848/nacos/v1/ns/instance/beat?serviceName=k8s-spring-cloud-admin.base&beat=%7b%22cluster%22%3a%22DEFAULT%22%2c%22ip%22%3a%2210.43.39.114%22%2c%22metadata%22%3a%7b%7d%2c%22port%22%3a15005%2c%22scheduled%22%3atrue%2c%22serviceName%22%3a%22k8s-spring-cloud-admin.base%22%2c%22weight%22%3a1%7d",
                    null, null);
            // System.out.println(rep.getCode());
            // System.out.println(new String(rep.getBody()));

            Thread.sleep(10000L);
        }

    }
}
